package com.yc.c118s3plyqnzf;

import com.yc.c118s3plyqnzf.controller.LoginInterceptor;
import com.yc.c118s3plyqnzf.util.LocalDateConvertor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 主类
// 1. Spring 配置类
// 2. 应用的启动类
@SpringBootApplication
@RestController
// Mapper扫描，将 mapper 添加到 IOC 容器中
@MapperScan("com.yc.c118s3plyqnzf.mapper")
public class C118S3PlyQnzfApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(C118S3PlyQnzfApplication.class, args);
    }

    @GetMapping("hello")
    public String hello(String name){
        return "hello " + name;
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 用于注册web拦截器，静态资源可以被拦截
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/add.html");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 静态资源映射
        registry.addResourceHandler("/**").addResourceLocations(
                "file:/C:/Users/念流年/yc118/yc118/C118-S3-Ply-qnzf/src/main/resources/static/");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        System.out.println("===============addFormatters==============");
        // 注册类型转换器
        registry.addConverter(new LocalDateConvertor());
    }
}
